/**
 * 
 */
package filesystem;

import java.awt.Component;

import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

class FileSystemTreeRenderer extends DefaultTreeCellRenderer {
	private final DirectoryChooserPanel chooserUI;

	/**
	 * @param chooserUI
	 */
	FileSystemTreeRenderer(DirectoryChooserPanel chooserUI) {
		this.chooserUI = chooserUI;
	}

	public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
		super.getTreeCellRendererComponent(tree, value, sel, expanded, false,
		// even "leaf" folders should look like other folders
				row, hasFocus);

		if (value instanceof FileNode) {
			FileNode node = (FileNode) value;
			setText(this.chooserUI.getFileView().getName(node.getFile()));
			setIcon(this.chooserUI.getFileView().getIcon(node.getFile()));
		}

		return this;
	}
}
